#include <stdio.h>

// judge.c

void usage( char **argv ) {

  printf( "usage : %s <binary file>\n", argv[ 0 ] ) ;
  return ;

}


int main( int argc, char **argv ) {

  FILE *fp ;
  int c ;
  unsigned int i = 0, head_addr = 0, valid = 0 ;

 
  if( argc != 2 ) {
    usage( argv ) ;
    return -1 ;
  }

  if( ! ( fp = fopen( argv[ 1 ], "rb" ) ) ) {
    printf( "failed to open file.\n" ) ;
    return -1 ;
  }

  while( ( c = getc( fp ) ) != EOF ) {

    if( i == 0 ) {
      if( c != 77 )
        break ;
    } else if( i == 1 ) {
      if( c != 90 )
        break ;
    } else if( i >= 60 && i <= 63 ) {
      head_addr += ( c << ( ( i - 60 ) * 8 ) ) ;
    } else if( head_addr ) {
      if( i == head_addr ) {
        if( c != 80 )
          break ;
      } else if( i == head_addr + 1 ) {
        if( c != 69 )
          break ;
      } else if( i == head_addr + 2 ) {
        if( c != 0 )
          break ;
      } else if( i == head_addr + 3 ) {
        if( c == 0 )
          valid = 1 ;
        break ;
      } else if( i > head_addr + 3 ) {
        break ;
      }
    }

    i++ ;

  }

  if( valid )
    printf( "this file is PE.\n" ) ;
  else
    printf( "this file is not PE.\n" ) ;

  fclose( fp ) ;

  return 0 ;

}
